OPC Studio User's Guide and Reference
Installed Examples - WindowsForms - ValueToMessageBox

Very simple Windows Forms application that reads and displays an OPC "Classic" item value in a message box after the user clicks on a button.

The form:

// $Header: $
// Copyright (c) CODE Consulting and Development, s.r.o., Plzen. All rights reserved.

//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

using System;
using System.Windows.Forms;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

namespace ValueToMessageBox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Create EasyOPC-DA component
            var client = new EasyDAClient();

            // Read item value and display it in a message box
            try
            {
                object value = client.ReadItemValue("", "OPCLabs.KitServer.2", "Demo.Single");
                MessageBox.Show(value?.ToString());
            }
            catch (OpcException opcException)
            {
                MessageBox.Show($"*** {opcException.Message}");
            }
        }
    }
}
' $Header: $
' Copyright (c) CODE Consulting and Development, s.r.o., Plzen. All rights reserved.

'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel

Public Class Form1

    ' ReSharper disable InconsistentNaming
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles Button1.Click
        ' ReSharper restore InconsistentNaming

        ' Create EasyOPC-DA component
        Dim easyDaClient As New OpcLabs.EasyOpc.DataAccess.EasyDAClient

        ' Read item value and display it in a message box
        Try
            MessageBox.Show(easyDaClient.ReadItemValue("", "OPCLabs.KitServer.2", "Demo.Single"))
        Catch opcException As OpcException
            MessageBox.Show($"*** {opcException.Message}")
        End Try
    End Sub
End Class

 

See Also

Conceptual